﻿using Edge.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace Edge.Utilities.Tests
{
    
    
    /// <summary>
    ///This is a test class for DateTimeExtensionsTest and is intended
    ///to contain all DateTimeExtensionsTest Unit Tests
    ///</summary>
    [TestClass()]
    public class DateTimeExtensionsTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for FormatDateTime
        ///</summary>
        [TestMethod()]
        public void FormatDateTimeTest()
        {
            string value = "12/31/1971";
            bool includeTime = false;
            string expected = "31-DEC-1971";
            string actual;
            actual = value.FormatDateTime(includeTime);
            Assert.AreEqual(expected, actual);
        }


        /// <summary>
        ///A test for FormatDateTime
        ///</summary>
        [TestMethod()]
        public void FormatDateTimeTest2()
        {
            string value = "12/31/1971";
            bool includeTime = true;
            string expected = "31-DEC-1971 00:00:00";
            string actual;
            actual = value.FormatDateTime(includeTime);
            Assert.AreEqual(expected, actual);
        }


        /// <summary>
        ///A test for ToAgoString
        ///</summary>
        [TestMethod()]
        public void ToAgoStringTest()
        {
            DateTime value = DateTime.Now.AddDays(-16);
            string expected = "2 weeks ago";
            string actual;
            actual = DateTimeExtensions.ToAgoString(value);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for SubtractDays
        ///</summary>
        [TestMethod()]
        public void SubtractDaysTest()
        {
            DateTime dt = DateTime.Now;
            double value = 2;
            DateTime expected = DateTime.Now.AddDays(-2);
            DateTime actual;
            actual = DateTimeExtensions.SubtractDays(dt, value);
            Assert.AreEqual(expected.DayOfYear, actual.DayOfYear);
        }

        /// <summary>
        ///A test for Days
        ///</summary>
        [TestMethod()]
        public void DaysTest()
        {
            int expected = DateTime.Now.AddDays(2).DayOfYear;
            int actual;
            actual = 2.Days().FromNow.DayOfYear;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Days
        ///</summary>
        [TestMethod()]
        public void DaysTest2()
        {
            int expected = DateTime.Now.AddDays(-2).DayOfYear;
            int actual;
            actual = 2.Days().Ago.DayOfYear;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ToAge
        ///</summary>
        [TestMethod()]
        public void ToAgeTest()
        {
            DateTime value = DateTime.Parse("12/31/1971");
            int expected = Convert.ToInt32(DateTime.Now.Subtract(DateTime.Parse("12/31/1971")).TotalDays) / 365;
            int actual;
            actual = DateTimeExtensions.Age(value);
            Assert.AreEqual(expected, actual);
        }
    }
}
